package com.copa.utils;

import catcode.CatCodeUtil;
import catcode.CodeBuilder;
import com.copa.entity.Music;
import com.copa.entity.News;
import org.jetbrains.annotations.NotNull;

/**
 * @author copa
 * @createDate 2022-02-16 22:23
 * @function 猫猫码封装工具
 */
public class MyCatCodeUtil {

    /**
     * 拼接分享音乐链接
     * @return
     */
    public static String getMusicStr(Music music) {
        CodeBuilder<String> builder = getStringCodeBuilder("music");
        return builder.key("type").value(music.getType())
                .key("musicUrl").value(music.getMusicUrl())
                .key("title").value(music.getTitle())
                .key("pictureUrl").value(music.getPictureUrl())
                .key("jumpUrl").value(music.getJumpUrl())
                .key("brief").value(music.getBrief())
                .key("summary").value(music.getSummary())
                .build();
    }

    /**
     * 骰子
     * @return
     */
    public static String getDice() {
        CodeBuilder<String> builder = getStringCodeBuilder("dice");
        return builder.key("random").value("true")
                .build();
    }

    /**
     * 发新闻
     * @return
     */
    public static String getNews(String content) {
        CodeBuilder<String> builder = getStringCodeBuilder("message");
        return builder.key("text").value(content)
                .build();
    }

    /**
     * at人
     * @return
     */
    public static String getAtPerson(String qqNum) {
        CodeBuilder<String> builder = getStringCodeBuilder("at");
        return builder.key("code").value(qqNum)
                .build();
    }

    /**
     * 获取特定新闻
     * @return
     */
    public static String getShareNews(News news) {
        CodeBuilder<String> builder = getStringCodeBuilder("share");
        return builder.key("url").value(news.getHref())
                .key("title").value(news.getTitle())
                .key("content").value("热榜指数：" + news.getHotNum())
                .key("coverUrl").value(news.getImageUrl())
                .build();
    }

    /**
     * 获取构建器
     * @return
     */
    @NotNull
    private static CodeBuilder<String> getStringCodeBuilder(String type) {
        // 获取猫猫码工具
        CatCodeUtil util = CatCodeUtil.INSTANCE;

        // 获取构建器
        CodeBuilder<String> builder = util.getStringCodeBuilder(type, true);
        return builder;
    }



}
